package com.xiyueyezi.xiyueyezi;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.xiyueyezi.xiyueyezi.constant.Constant;
import com.xiyueyezi.xiyueyezi.utils.LinkifyUtils;

import java.util.HashMap;
import java.util.Map;

public class SplashActivity extends AppCompatActivity {

    private TextView ll_privacy_text2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_term_of_service);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        initView();
    }

    private void initView() {
        ll_privacy_text2 = findViewById(R.id.ll_privacy_text2);
        Map<String, Intent> links = new HashMap<>();
        links.put("《用户协议》", new Intent(this, MainActivity.class));
        links.put("《隐私政策》", new Intent(this, LoginActivity.class));
        ll_privacy_text2.setText(LinkifyUtils.createClickableSpans(
                Constant.term_Tips,
                links
        ));
        ll_privacy_text2.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());

    }

    public void onAgreeClick(View view) {
        SharedPreferences prefs = getSharedPreferences("xiyueyezi", MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean("isPrivacyPolicyAccepted", true);
        editor.apply();
        // 启动主界面
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        // 结束当前活动
        finish();
    }

    public void onDisAgreeClick(View view) {
        SharedPreferences prefs = getSharedPreferences("xiyueyezi", MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean("isPrivacyPolicyAccepted", false);
        editor.apply();
        // 结束当前活动
        finish();
    }
}